import { Response } from '@/utils/request/index'


const success = "success";
const warning = "warning";
const delay = 2000;

function popupDialog(dialog: any, title: string,
                     content: string, type: string,
                     delay: number
){
    dialog.create({
        title: title,
        content: content,
        duration: delay,
        type: type
    })
}

/**
 * 自定义
 * @param dialog
 * @param title
 */
export function resultCustom(dialog:any, title: string) {
    popupDialog(dialog, title,  '', success, delay)
}

export function resultCodeNotify(dialog: any, title: string, result: Response) {
    let content = result.message === null ? "" : result.message
    let type;
    switch (result.code) {
        case 200:
            title += "成功"
            type = success;
            break;
        default:
            type = warning;
            break;
    }
    popupDialog(dialog, title, content, type, delay);
}
